package com.example.community.del;

import com.example.community.dao.RoomDao;
import com.example.community.model.Room;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/roomDeleteServlet")
public class RoomDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String rNo = req.getParameter("rNo");
        RoomDao roomDao = new RoomDao();
        Room room = roomDao.fandById(Integer.parseInt(rNo));
        if (room.getUsNo() == null){
            Integer delete = roomDao.delete(Integer.parseInt(rNo));
            if (delete == 1){
                // 删除成功
                resp.getWriter().write("true");
//                System.out.println("删除成功");
            }else {
                // 删除失败
                resp.getWriter().write("false");
//                System.out.println("删除失败");
            }
        }else {
            resp.getWriter().write("qita");
        }
    }
}
